<?php

namespace polymerize\user\module\user;

use app\common\InstanceTrait;
use app\model\User as UserModel;
use app\model\UserToken;
use support\Cache;

class CancelUser
{
    use InstanceTrait;

    /**
     * 删除注销用户
     *
     * @param int $uid
     * @param string $sessionId
     * @return bool
     */
    public function cancelUser(int $uid, string $sessionId): bool
    {
        Cache::delete(UID_SESSION_KEY . '_' . $sessionId);
        UserToken::where('uid', $uid)->delete();
        return UserModel::where('id', $uid)->delete();
    }
}
